<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ page isELIgnored="false" %>

<%
    String path = request.getContextPath();
%>

<jsp:include page="/admin/inc/incHead.jsp" flush="false"/>

<script language="javascript">
    var click = false;
    dwr.engine.setAsync(false);
    function goodClassSelect() {
        if (click == 0) {
            document.getElementById("indicator").style.display = "block";
            ClassService.query(0, 20, callback);
            click = 1;
        }
    }

    function callback(data) {
        var d = JSON.parse(data);
        document.getElementById("indicator").style.display = "none";
        console.log(d);
        dwr.util.addOptions("classIdElem", d, "classId", "className");
    }


    function check() {
        if (document.formAdd.classId.selectedIndex < 0) {
            alert("请选择类别");
            return false;
        }
        if (document.formAdd.goodName.value.length < 1) {
            alert("请填写商品名称");
            return false;
        }
        var ue = UE.getEditor('container');
        if (ue.getContentTxt().length < 10) {
            alert("请输入公告内容,至少10字");
            return;
        }
        if (document.formAdd.goodPrice.value.length < 1) {
            alert("请填写价格");
            return false;
        }
        if (document.formAdd.goodInventory.value.length < 1) {
            alert("请填写商品库存");
            return false;
        }

        document.formAdd.submit();
    }
</script>
<form action="<%=path %>/good/goodAdd.action" name="formAdd" method="post" enctype="multipart/form-data">
    <table align="center" class="table table-bordered">
        <tr bgcolor="#EEF4EA">
            <td colspan="3" class='title'><span>点卡添加</span></td>
        </tr>
        <tr align='center'>
            <td width="25%" align="right">
                商品类别：
            </td>
            <td width="75%" align="left">
                <table>
                    <tr>
                        <td>
                            <select name="classId" id="classIdElem" onclick="goodClassSelect()">
                                <%--<option disabled>--请选择商品类别--</option>--%>
                            </select>
                        </td>
                        <td>
                            <img id="indicator" src="<%=path %>/img/loading.gif" style="display:none"/>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr align='center'>
            <td width="25%" align="right">
                点卡名称：
            </td>
            <td width="75%" align="left">
                <input type="text" name="goodName" size="50"/>
            </td>
        </tr>
        <tr align='center'>
            <td width="25%" align="right">
                点卡介绍：
            </td>
            <td width="75%" align="left">
                <script id="container" name="goodInfo" type="text/plain"></script>
            </td>
        </tr>
        <tr align='center'>
            <td width="25%" align="right">
                图片：
            </td>
            <td width="75%" align="left">
                <s:file name="upload"/>
            </td>
        </tr>
        <tr align='center'>
            <td width="25%" align="right">
                价格：
            </td>
            <td width="75%" align="left">
                <input type="text" name="goodPrice" size="20" onkeyup="this.value=this.value.replace(/\D/g,'')"
                       onafterpaste="this.value=this.value.replace(/\D/g,'')"/>
            </td>
        </tr>
        <tr align='center'>
            <td width="25%" align="right">
                库存：
            </td>
            <td width="75%" align="left">
                <input type="text" name="goodInventory" size="20"/>
            </td>
        </tr>
        <tr align='center'>
            <td width="25%" align="right">
                点卡状态：
            </td>
            <td width="75%" align="left">
                <input type="radio" name="goodState" value="0" checked/>下架
                <input type="radio" name="goodState" value="1"/>销售
            </td>
        </tr>
        <tr align='center'>
            <td width="25%" align="right">

            </td>
            <td width="75%" align="left">
                <input type="button" class="btn btn-info" value="提交" onclick="check()"/>
            </td>
        </tr>
    </table>
</form>
<script>
    var ue = UE.getEditor('container');
    ue.ready(reParentSize);
</script>
<script type='text/javascript' src='<%=path %>/dwr/interface/ClassService.js'></script>
<jsp:include page="/admin/inc/incFoot.jsp" flush="false"/>